package org.nfyszny.zzzs.modules.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.query.QueryGenerator;

import org.nfyszny.zzzs.modules.entity.ZzzsManagementOfHarvest;
import org.nfyszny.zzzs.modules.service.IZzzsManagementOfHarvestService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;


import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 采摘管理
 * @Author: jeecg-boot
 * @Date:   2022-11-10
 * @Version: V1.0
 */
@Api(tags="采摘管理")
@RestController
@RequestMapping("/modules/zzzsManagementOfHarvest")
@Slf4j
public class ZzzsManagementOfHarvestController extends JeecgController<ZzzsManagementOfHarvest, IZzzsManagementOfHarvestService> {
	@Autowired
	private IZzzsManagementOfHarvestService zzzsManagementOfHarvestService;
	
	/**
	 * 分页列表查询
	 *
	 * @param zzzsManagementOfHarvest
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "采摘管理-分页列表查询")
	@ApiOperation(value="采摘管理-分页列表查询", notes="采摘管理-分页列表查询")
	@GetMapping(value = "/list")
	@AutoDict

	public Result<IPage<ZzzsManagementOfHarvest>> queryPageList(ZzzsManagementOfHarvest zzzsManagementOfHarvest,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<ZzzsManagementOfHarvest> queryWrapper = QueryGenerator.initQueryWrapper(zzzsManagementOfHarvest, req.getParameterMap());
		Page<ZzzsManagementOfHarvest> page = new Page<ZzzsManagementOfHarvest>(pageNo, pageSize);
		IPage<ZzzsManagementOfHarvest> pageList = zzzsManagementOfHarvestService.pageList(page, queryWrapper);
		return Result.TOK(pageList);
	}
	 /**
	  * 切换显示状态
	  */
	 @GetMapping("switchStatus")
	 public Result switchStatus(@RequestParam String id,@RequestParam Integer status) {
		 zzzsManagementOfHarvestService.switchStatus(id,status);
		 return Result.TOK();
	 }
	/**
	 *   添加
	 *
	 * @param zzzsManagementOfHarvest
	 * @return
	 */
	@AutoLog(value = "采摘管理-添加")
	@ApiOperation(value="采摘管理-添加", notes="采摘管理-添加")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_management_of_harvest:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody ZzzsManagementOfHarvest zzzsManagementOfHarvest) {
		zzzsManagementOfHarvestService.save(zzzsManagementOfHarvest);
		return Result.TOK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param zzzsManagementOfHarvest
	 * @return
	 */
	@AutoLog(value = "采摘管理-编辑")
	@ApiOperation(value="采摘管理-编辑", notes="采摘管理-编辑")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_management_of_harvest:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody ZzzsManagementOfHarvest zzzsManagementOfHarvest) {
		zzzsManagementOfHarvestService.updateById(zzzsManagementOfHarvest);
		return Result.TOK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "采摘管理-通过id删除")
	@ApiOperation(value="采摘管理-通过id删除", notes="采摘管理-通过id删除")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_management_of_harvest:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		zzzsManagementOfHarvestService.removeById(id);
		return Result.TOK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "采摘管理-批量删除")
	@ApiOperation(value="采摘管理-批量删除", notes="采摘管理-批量删除")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_management_of_harvest:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.zzzsManagementOfHarvestService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.TOK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "采摘管理-通过id查询")
	@ApiOperation(value="采摘管理-通过id查询", notes="采摘管理-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<ZzzsManagementOfHarvest> queryById(@RequestParam(name="id",required=true) String id) {
		ZzzsManagementOfHarvest zzzsManagementOfHarvest = zzzsManagementOfHarvestService.getById(id);
		if(zzzsManagementOfHarvest==null) {
			return Result.error("未找到对应数据");
		}
		return Result.TOK(zzzsManagementOfHarvest);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param zzzsManagementOfHarvest
    */
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_management_of_harvest:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZzzsManagementOfHarvest zzzsManagementOfHarvest) {
        return super.exportXls(request, zzzsManagementOfHarvest, ZzzsManagementOfHarvest.class, "采摘管理");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("zzzs_management_of_harvest:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZzzsManagementOfHarvest.class);
    }

}
